package com.bs.bsacexj.service.Job;

import com.bs.bsacexj.common.constant.Constants;
import com.bs.bsacexj.common.core.redis.RedisCache;
import com.bs.bsacexj.domain.AccessControlEventInfoVO;
import com.bs.bsacexj.service.impl.UploadACEventInfoService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import org.springframework.util.CollectionUtils;
@Slf4j
@Component
public class UploadACEventInoJob implements Job {
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private UploadACEventInfoService uploadACEventInfoService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("执行门禁事件数据上传任务");
        //STEP1 查询30秒内的门禁记录
        List<AccessControlEventInfoVO>  list=redisCache.getCacheList(Constants.WAIT_ACEEVENT_RECORD_KEY);
        //STEP2 利用redis的原子性，清空数据
        redisCache.deleteObject(Constants.WAIT_ACEEVENT_RECORD_KEY);
        //STEP2 分段开始上传
        if(!CollectionUtils.isEmpty(list)){
            uploadACEventInfoService.uploadACEventInfo(list);
        }

    }
}
